package com.bmft.hello.test;

import org.apache.http.HttpHost;
import org.elasticsearch.client.AsyncSearchClient;
import org.elasticsearch.client.RestClient;
import org.elasticsearch.client.RestHighLevelClient;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;

import java.io.IOException;

/**
 * @author Jarvan
 * @version 1.0
 * @create 2020/11/4 18:34
 */
@SpringBootTest
@RunWith(SpringRunner.class)
public class EnvironmentTest01 {
    @Autowired
    //如果你的对象名和bean的方法名称不一致需要@Qualifier
    @Qualifier("restHighLevelClient")
    private RestHighLevelClient restHighLevelClient;
    @Test
    public void test() {
        System.out.println(restHighLevelClient);
        AsyncSearchClient asyncSearchClient = restHighLevelClient.asyncSearch();

    }

    @Test
    public void test02() throws IOException {
        RestHighLevelClient client = new RestHighLevelClient(
                RestClient.builder(
                        new HttpHost("localhost", 9300, "http")));
        System.out.println(client);
        client.close();
    }
}
